# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

pkgbase=mpdecimal
pkgname=('mpdecimal' 'mpdecimal-devel')
pkgver=2.4.2
pkgrel=2
pkgdesc="Package for correctly-rounded arbitrary precision decimal floating point arithmetic"
arch=('i686' 'x86_64')
url="https://www.bytereef.org/mpdecimal/index.html"
license=('custom')
depends=('gcc-libs')
checkdepends=('wget')
source=("http://www.bytereef.org/software/${pkgname}/releases/${pkgname}-${pkgver}.tar.gz"
        "msys2-mingw-fixes.patch")
sha512sums=('eb18ad53b81b93c469db4d915bbb3fae21b36ad82a88e01fef3a6946ac5f50b54376e259a5ecbe23836f1efd59d226b942ecdee87eaba7f9e75cdcaaa9499ef7'
            '1418b4d40d6c8e693aa1125c78a5e9a2d6fd9361f92785b9d7b0932dc226a09ee74a9c744ef5a14e0c28227d8cae71dbd36a535dbf21f367617adf80925fc7ae')

prepare() {
  cd ${pkgname}-${pkgver}
  patch -Nbp1 -i ${srcdir}/msys2-mingw-fixes.patch
  autoreconf -fiv
}

build() {
  cd ${pkgname}-${pkgver}

  ./configure --prefix=/usr
  make
  make DESTDIR=${srcdir}/dest install
}

check() {
  cd ${pkgname}-${pkgver}
  make check
}

package_mpdecimal() {
  depends=('msys2-runtime' 'gcc-libs')
  cd ${srcdir}/dest
  
  mkdir -p ${pkgdir}/usr/bin
  cp -rf ${srcdir}/dest/usr/bin ${pkgdir}/usr/
  install -Dm644 ${srcdir}/${pkgname}-${pkgver}/LICENSE.txt "${pkgdir}"/usr/share/licenses/${pkgname}/LICENSE.txt
}

package_mpdecimal-devel() {
  depends=("mpdecimal=${pkgver}")
  pkgdesc="mpdecimal headers and libraries"

  cd ${srcdir}/dest
#  mkdir -p ${pkgdir}/usr/include
#  mkdir -p ${pkgdir}/usr/lib
#  mkdir -p ${pkgdir}/bin/share
  cp -rf usr ${pkgdir}/usr
  rm -r ${pkgdir}/usr/bin
}
